Skip to content

feat(k8s): the runtime sweep is discovery-driven, bounded by namespaces instead of kinds (#1517) - #1609

Merged
lex00 merged 1 commit into
mainfrom
feat/1517-discovery-runtime-sweep
Aug 9, 2026
Merged

lex00 merged 1 commit into
mainfrom
feat/1517-discovery-runtime-sweep

Conversation

@lex00

@lex00 lex00 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Closes #1517.

#1518 widened the #1077 Pod scan to the estate's own declared API groups, but the bound was still a kind list: children in groups the estate never declares — a CR's Deployments, anything an operator makes outside its own group — never surfaced as runtime children, and operator estates are exactly where the runtime tier matters most.

The sweep now inverts to discovery-driven, per the issue's direction:

  • K8sClient gains preferredGroupVersions() — one groupVersion per served group (the group's own preferredVersion), derived from the same root discovery servedGroupVersions already fetched, now shared through a single cached structure. One version per group means every kind is listed exactly once.
  • The sweep lists every listable kind those groupVersions serve. Its bound is reach, not a table:
    • namespaced kinds only in the namespaces the declared estate touches (plus GitOps target namespaces) — owner references cannot cross a namespace;
    • cluster-scoped kinds only when a declared cluster-scoped entity resolved — a cluster-scoped object's owners are themselves cluster-scoped (the GC's own rule);
    • Events skipped (both groups): they point at their subject via involvedObject, never ownerReferences, so listing them can only cost.
  • The standing guards hold: outside Pods (whose full chain verdicts are feat(core): classify owner-referenced children as runtime, not orphans #1077's original contract), a swept object is reported only when its owner chain — or the epic: GitOps controllers as deploy units + observed convergence (Argo CD, Flux) #1549 label channel, which is untouched and still covered by its tests — resolves to a declared entity. The sweep is not an inventory.
  • Tri-state honesty extends to the sweep: a kind discovery names but a list fails (RBAC denial, flaking apiserver) becomes a runtime-sweep:<gv>/<Kind> entry in unobserved with classifyApiFailure's own verdict (403 → no-credentials), recorded once per kind naming the scopes that failed. A list 404 stays an absence; declared-entity resolution is never failed by the sweep.

The lexicon's optional dependency on @intentius/chant-k8s-client moves to ^0.42.1: the old ^0.41.5 range excluded the workspace's 0.42.1, so npm nested the published 0.41.20 under lexicons/k8s and the lexicon build typechecked against a client without the new method.

Tests (fakeCluster-driven, no cluster contacted):

  • a declared MicroVMReplicaSet's controller-made MicroVMs surface with ownerChain: { root: "declared" } — the issue's own estate;
  • a declared RayCluster's Deployment child surfaces even though apps/v1 is never declared — the group-list inversion;
  • a 403 on a discovered kind's list yields runtime-sweep:batch/v1/Job unobserved, never silence; same for the Pod list;
  • a cluster-scoped child chains to a declared Namespace; without a cluster-scoped declaration, no cluster-scoped kind is listed;
  • the sweep's reads all stay inside the estate's namespaces, and Events are never listed.

k8s lexicon suite 63 files / 1282 passed; client suite passes with a new preferredGroupVersions test (preferred-per-group, fallback when a group reports none, cached root discovery); npm run build green for both packages; eslint clean.

…es instead of kinds (#1517)

The runtime-children sweep bounded itself by kind: first Pods (#1077),
then the estate's own declared API groups (#1518). Both miss where the
runtime tier says the most — an operator's children are whatever kinds
its controllers make, including kinds in groups the estate never
declares (a CR's Deployments, a chain through a foreign CRD group), and
no kind list can anticipate them.

The sweep now asks the cluster itself. K8sClient gains
preferredGroupVersions() — one groupVersion per served group, from the
same cached root discovery servedGroupVersions reads — and the sweep
lists every listable kind those serve. What bounds it is reach, not a
table:

- namespaced kinds are listed only in the namespaces the declared
  estate touches (owner references cannot cross a namespace);
- cluster-scoped kinds are listed only when a declared cluster-scoped
  entity resolved (a cluster-scoped object's owners are cluster-scoped,
  Kubernetes' own GC rule);
- Events are skipped: they name their subject via involvedObject, never
  ownerReferences, so listing them can only cost;
- outside Pods, a swept object is still only reported when its owner
  chain (or the #1549 label channel) resolves to a declared entity —
  the sweep is not an inventory.

Tri-state honesty extends to the sweep: a kind discovery names but the
sweep cannot list (RBAC denial, a flaking apiserver) becomes a
runtime-sweep:* entry in unobserved — recorded once per kind, naming
the scopes that failed — never a silent gap that would read as "no
runtime children there". A list 404 stays an absence, and declared
resolution is never failed by the sweep.

The k8s lexicon's optional client dependency moves to ^0.42.1 so the
workspace client (which carries the new method) links instead of the
published 0.41.20 nesting under lexicons/k8s.
@lex00
lex00 merged commit b56bac0 into main Aug 9, 2026
5 checks passed
lex00 added a commit that referenced this pull request Aug 9, 2026
… publish gate (#1616)

The release recipe rewrites @intentius/* peerDependencies to the new
version but left optionalDependencies alone, so lexicons/k8s kept
@intentius/chant-k8s-client at ^0.42.1 across the 0.44.0 bump. Under 0.x
semver that range excludes the workspace's 0.44.0, npm nests the published
0.42.1, and publish.yml's test job typechecks the lexicon against a client
missing contextLabel (#1610) and preferredGroupVersions (#1609) — which is
exactly how the chant-v0.44.0 publish run died before publishing anything.

Pins the dep to ^0.44.0 now and teaches the recipe to rewrite
@intentius/* optionalDependencies (a literal "*" stays untouched) so the
next lockstep bump carries it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Runtime tier misses custom-resource children: an owner chain through a CRD kind never surfaces

1 participant